<template>
	<div>
    <Modal v-model="modal11">
      <img :src="url"/>
    </Modal>
		<h1 style="text-align: center;margin: 20px;">房屋求购</h1>
		<div class="content">
			<div class="width1190">
				<form action="#" method="get" class="pro-search">
					<table>
						<tbody>
							<tr>
								<th>搜索：</th>
								<td>  
										<Input @on-change="doHouseBuySearch()" v-model="searchCon.title" style="width:150px;" placeholder="请输入标题"></Input>
								</td>
								<th>描述：</th>
								<td>  
										<Input @on-change="doHouseBuySearch()" v-model="searchCon.detail" style="width:150px;" placeholder="请输入描述"></Input>
								</td>
							</tr>
						</tbody>
					</table>
				</form>
				
				<!-- <button @click="doHouseBuySearch"> 搜索</button> -->
				
			</div>
			
			<!--width1190/-->
			<div class="width1190">
				<div class="index-fang-list">
					<dl class="index-item" v-for="(item, index) in houseArray" v-bind:info="item">
						<Card>
							<div @click="detailHouseBuy(item.houseBuyId)">
								<p slot="title">{{item.title}}</p>
								<p>{{item.detail}}</p>
								
								<p>{{item.ct}}</p>
							</div>
							
						</Card>
					</dl>
				</div>
				

				<div class="clears"></div>
				<div class="page">
					<Page
					      :page-size="searchCon.pageSize"
					      @on-change="pageSearch"
					      :total="searchCon.total"
					      :current="searchCon.currentPage" />
				</div>
			</div>
			<!--width1190/-->
		</div>
	</div>
</template>

<script>
	export default {
		data: function() {
			return {
        iport : '',
        modal11 : false,
        number :10,
        orderInfo : {},
				currentUser:{},
				searchCon: {
						title: null,
						detail : null,
						currentPage: null,
						pageSize: null,
						total:null,
				},
				houseArray: [
					
					
				]
			};
		},
		methods: {
      getOrderStatu: function () {
        console.log(this.$data.number);
        this.number--;
        if(this.number === 0){
          clearInterval(this.longSearch)
          this.modal11 = false
          this.number = 10
          this.$Notice.error({
            title: '支付超时',
          });
        }
        //发请求查询支付状态
        this.http.get({
          url: "/pay-order/info",
          param: {

            orderNumber:this.orderInfo.orderNumber
          }
        }).then(data => {

          console.log("支付状态" + data);

          if(data == 2) {
            this.modal11 = false
            clearInterval(this.longSearch)


            this.$Notice.success({
              title: '支付成功',
            });

          }
        })

      },
      detailHouseBuy: function(houseBuyId) {
        this.searchCon.clientId = JSON.parse(sessionStorage.getItem('CURRENT')).client.clientId;
        console.log(this.searchCon.clientId);
        this.http.get({
          url: "/quotarecord/info",
          param: {
            clientId: this.searchCon.clientId,
            orderTypeId : 12
          }
        }).then(data => {
          if(data.quota +1 > 0){
            this.$router.push({
              name:'house_buy_detail',
              params:{
                houseBuyId
              }
            })
          } else{
            let paramm = {};
            this.http.post({
              url:'/pay-order/info',
              param:{
                clientId:this.searchCon.clientId,
                orderTypeId:12
              }
            })
                .then((data) => {
                  this.$data.orderInfo = data
                  paramm.clientId = this.$data.orderInfo.clientId;
                  paramm.orderNumber = this.$data.orderInfo.orderNumber;
                  paramm.price = this.$data.orderInfo.price;
                  paramm.orderTypeId = this.$data.orderInfo.orderTypeId;
                  this.modal11 = true;
                  this.url =  this.iport + 'pay/nativeV2?clientId='+paramm.clientId
                      +'&orderTypeId='+paramm.orderTypeId
                      +'&money='+paramm.price
                      +'&orderNumber='+paramm.orderNumber
                  this.longSearch = setInterval(this.getOrderStatu,3000)
                })
          }
          console.log(data);
        });

			},
			pageSearch: function(changedPage) {
			  this.$data.searchCon.currentPage = changedPage
			  this.doHouseBuySearch(changedPage)
			},
			doHouseBuySearch:function(current){
				console.log("打印title");
				console.log(this.searchCon.title);
				console.log("打印detials")
				console.log(this.searchCon.details);
				
				this.http.get({
						url : "/house-buy-client-vo/page",
						param:{
							title : this.searchCon.title,
							detail: this.searchCon.detail,
							pageSize: this.searchCon.pageSize,
							currentPage: current
						}
					}).then(data => {
						console.log("买房信息为 : ");
						console.log(data);
						this.$data.searchCon.pageSize = data.size,
						this.$data.searchCon.currentPage = data.current,
						this.$data.searchCon.total = data.total
						this.$data.houseArray = data.records
					})				
			}
	},
	created: function() {
		this.$data.currentUser = JSON.parse(sessionStorage.getItem('CURRENT'))
		this.$data.searchCon.clientId = this.$data.currentUser.client.clientId
    this.iport = this.store.state.iport
    this.doHouseBuySearch(1)
		
		
	},
	beforeRouteLeave(to, from, next) {
	    this.$destroy();//手动销毁当前页面
	    next();
	},
}	
</script>

<style>
	.buy-item {
		
	}
</style>
